package com.yuan.zs.ui;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.FrameLayout;

import com.yuan.base.framework.BaseTokenManager;
import com.yuan.zs.R;


/**
 * 应用入口
 */
public class AppStartActivity extends AppCompatActivity implements AnimationListener {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_app_start);
		FrameLayout fl_layout = findViewById(R.id.fl_layout);

		Animation alphaAnimation = AnimationUtils.loadAnimation(this, R.anim.app_start_alpha);
		alphaAnimation.setFillEnabled(true); // 启动Fill保持
		alphaAnimation.setFillAfter(true); // 设置动画的最后一帧是保持在View上面
		fl_layout.setAnimation(alphaAnimation);
		alphaAnimation.setAnimationListener(this); // 为动画设置监听
	}

	@Override
	public void onAnimationStart(Animation animation) {
	}

	@Override
	public void onAnimationEnd(Animation animation) {
		// 动画结束时结束欢迎界面并转到软件的主界面
		Intent intent = new Intent();
//		if (AppUtil.isFirstUse()) {
//			intent.setClass(this, GuideActivity.class);
//		} else {
		if (TextUtils.isEmpty(BaseTokenManager.getToken())) {
			intent.setClass(this, LoginActivity.class);
		} else {
			intent.setClass(this, MainActivity.class);
		}
//		}
		startActivity(intent);
		finish();
	}

	@Override
	public void onAnimationRepeat(Animation animation) {

	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// 在欢迎界面屏蔽BACK键
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			return false;
		}
		return false;
	}
}
